//
//  ViewController.m
//  客户端
//
//  Created by 袁飞霞 on 16/5/17.
//  Copyright © 2016年 cn.sophietobeabetterone. All rights reserved.
//

#import "ViewController.h"
#import <GCDAsyncSocket.h>

@interface ViewController ()<GCDAsyncSocketDelegate>
@property (nonatomic, strong)  GCDAsyncSocket * clientSocket;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.clientSocket connectToHost:@"127.0.0.1" onPort:1234 error:nil];
    [self.clientSocket writeData:[@"i am ios client" dataUsingEncoding:NSUTF8StringEncoding ] withTimeout:-1 tag:0];
    
}
-(GCDAsyncSocket *)clientSocket
{
    if (_clientSocket == nil) {
        _clientSocket = [[GCDAsyncSocket alloc]initWithDelegate:self delegateQueue:dispatch_get_main_queue()];
        
    }
    return _clientSocket;
}
#pragma mark -----GCDAsyncSocketDelegate-----
-(void)socket:(GCDAsyncSocket *)sock didConnectToHost:(NSString *)host port:(uint16_t)port
{
NSLog(@"%s", __FUNCTION__);
}
-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{

}
-(void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
{

}

@end
